import type { NewProduct, NewProductPageParams, NewProductParams, NewProductSortParams, NewProductUpdateParams } from '@/models/newProduct'
import type { CommonResult, CommonPage } from '@/models/request'
import request, { ContentTypeEnum } from '@/utils/request'

export function fetchList(params: NewProductPageParams) {
  return request<CommonPage<NewProduct>>({
    url: '/home/newProduct/list',
    method: 'get',
    params: params,
  })
}

export function updateRecommendStatus(data: NewProductUpdateParams) {
  return request<CommonResult>({
    url: '/home/newProduct/update/recommendStatus',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}

export function deleteNewProduct(data: { ids: string }) {
  return request<CommonResult>({
    url: '/home/newProduct/delete',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}

export function createNewProduct(data: NewProductParams) {
  return request<CommonResult>({
    url: '/home/newProduct/create',
    method: 'post',
    data: data,
  })
}

export function updateNewProductSort(params: NewProductSortParams) {
  return request<CommonResult>({
    url: '/home/newProduct/update/sort/' + params.id,
    method: 'post',
    params: params,
  })
}
